//
//  Student.cpp
//  宿舍管理系统
//
//  Created by 孟强定 on 2020/6/26.
//  Copyright © 2020 mqd. All rights reserved.
//
#include "list.hpp"
#include "Student.hpp"

std::string Student::projects[]={"计算机","电气","信工"};
std::string toString(int x, int num);
int Student::idCnt=0;
Student::Student(std::string name, std::string major, int id, int grade, int _class){
    this->name=name;
    this->major=major;
    this->id=id;
    this->grade=grade;
    this->_class=_class;
}
Student::Student(){
    name=major;
    id=grade=_class=0;
    for(int i=0;i<4;i++) roomInfo[i]=0;
}
std::string randName();
void Student::initName(){
    name= randName();
}
void Student::randMajor(){
    major=Student::projects[rand()%3];
}
void Student::randId(){
    id=++Student::idCnt;
}
void Student::randGrade(){
    grade= 2018;
}
void Student::randClass(){
    _class= rand()%3+1;
}
void Student::init(){
    initName();
    randMajor();
    randId();
    randGrade();
    randClass();
}

void Student::print(){
    for(int i=1;i<=20;i++) std::cout<<"-";
    std::cout<<std::endl;
    std::cout<<"  姓名: "<<name<<std::endl;
    std::cout<<"  学号: "<<id<<std::endl;
    std::cout<<"  专业: "<<major<<std::endl;
    std::cout<<"  班级: "<<_class<<std::endl;
    std::cout<<"  年级: "<<grade<<std::endl;
    std::cout<<"  宿舍: "<<this->getRoom();
    std::cout<<std::endl;
}
int Student::getBuildingId(){
    return roomInfo[0];
}
int Student::getFloorId(){
    return roomInfo[1];
}
int Student::getRoomId(){
    return roomInfo[2];
}
int Student::getbedId(){
    return roomInfo[3];
}
std::string Student::getName(){
    return name;
}

int Student::getId(){
    return id;
}

std::string Student::getRoom(){
    std::string s="";
    if (!roomInfo[0]) return s="未分配";
    s+=toString(roomInfo[0],1)+'-'+toString(roomInfo[1],1)+toString(roomInfo[2],2);
    s+=" "+toString(roomInfo[3],1)+"号床";
    return s;
}

void Student::setRoom(int building ,int floor, int room, int bed){
    roomInfo[0]=building;
    roomInfo[1]=floor;
    roomInfo[2]=room;
    roomInfo[3]=bed;
}

bool Student::delRoom(){
    if (!roomInfo[0]) return 0;
    for(int i=0;i<4;i++) roomInfo[i]=0;
    return 1;
}

